import ByteArray = require("bytearray-node");
type int = number;
//class FyMapInfo

export class FyMapInfo {
  constructor() {
    
    this.mapData = new Array<any>();
    return;
  }

  public read(arg1: ByteArray, arg2: Boolean = true): void {
    var loc3 = null;
    var loc4 = 0;
    var loc5 = 0;
    if (arg2) {
      arg1.uncompress();
    }
    // arg1.endian = flash.utils.Endian.LITTLE_ENDIAN;
    this.mapId = arg1.readInt();
    this.pieceWidth = arg1.readInt();
    this.pieceHeight = arg1.readInt();
    this.gridXNum = arg1.readInt();
    this.gridYNum = arg1.readInt();
    this.gridWidth = arg1.readInt();
    this.gridHeight = arg1.readInt();
    this.connectedPointY = arg1.readInt();
    var loc1 = this.readSize(arg1);
    var loc2 = 0;
    while (loc2 < loc1) {
      loc3 = new Array<any>();
      loc4 = this.readSize(arg1);
      loc5 = 0;
      while (loc5 < loc4) {
        loc3[loc5] = arg1.readByte();
        ++loc5;
      }
      this.mapData[loc2] = loc3;
      ++loc2;
    }
    return;
  }

  public write(arg1: Boolean = true): ByteArray {
    var loc2 = null;
    var loc4 = 0;
    var loc1 = new ByteArray();
    loc1.endian = "LE";
    // loc1.endian = flash.utils.Endian.LITTLE_ENDIAN;
    loc1.writeInt(this.mapId);
    loc1.writeInt(this.pieceWidth);
    loc1.writeInt(this.pieceHeight);
    loc1.writeInt(this.gridXNum);
    loc1.writeInt(this.gridYNum);
    loc1.writeInt(this.gridWidth);
    loc1.writeInt(this.gridHeight);
    loc1.writeInt(this.connectedPointY);
    this.writeSize(loc1, this.mapData.length);
    var loc3 = 0;
    while (loc3 < this.mapData.length) {
      loc2 = this.mapData[loc3];
      this.writeSize(loc1, loc2.length);
      loc4 = 0;
      while (loc4 < loc2.length) {
        loc1.writeByte(loc2[loc4]);
        ++loc4;
      }
      ++loc3;
    }
    if (arg1) {
      loc1.compress();
    }
    return loc1;
  }

  public writeSize(arg1: ByteArray, arg2: int): void {
    if (arg2 < 255) {
      arg1.writeByte(arg2);
    } else {
      arg1.writeByte(255);
      arg1.writeInt(arg2);
    }
    return;
  }

  public readSize(arg1: ByteArray): int {
    var loc1 = arg1.readUnsignedByte();
    if (loc1 == 255) {
      return arg1.readInt();
    }
    return loc1;
  }

  public /* var */ mapId!: int;

  public /* var */ pieceWidth!: int;

  public /* var */ pieceHeight!: int;

  public /* var */ gridXNum!: int;

  public /* var */ gridYNum!: int;

  public /* var */ gridWidth!: int;

  public /* var */ gridHeight!: int;

  public /* var */ connectedPointY!: int;

  public /* var */ mapData!: Array<any>;
}
